#include <iostream>
#include <functional>
#include <unistd.h>
#include <signal.h>

using namespace std;

void handler(int signo) {
    cout << "捕捉 [" << signo << "] " << "信号" << endl;
    sigset_t pendings;
    while (true) {
        cout << '.' << endl;
        sigpending(&pendings);
        for (int i = 1; i <= 31; i ++) {
            if (sigismember(&pendings, i)) cout << '1';
            else cout << '0';
        }
        cout << endl;
        sleep(1);
    }
}

int main() {
    // struct sigaction
    struct sigaction act, o_act;
    // SIG_IGN 其实就是被 函数指针强转的1 的宏
    act.sa_handler = handler; 
    act.sa_flags = 0;
    sigemptyset(&act.sa_mask);
    sigaddset(&act.sa_mask, 3);

    sigaction(2, &act, &o_act);

    while (true) {
        sleep(1);
    }

    return 0;
}
